package com.jackie.tongzhuang.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jackie.tongzhuang.Models.GongHuoShang;
import com.jackie.tongzhuang.R;

import java.util.List;

public class GongHuoShangAdapter extends BaseAdapter {
    private Context context;
    private List<GongHuoShang> items;

    public GongHuoShangAdapter(Context context, List<GongHuoShang> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public int getPosition(String str){
        int rowid = -1;
        for(int i = 0;i<items.size();i++){
            if(items.get(i).getMingCheng().equals(str)){
                return i;
            }
        }
        return rowid;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.control_spinner, parent, false);
        }
        TextView text_name = convertView.findViewById(R.id.sp_name);
        text_name.setText("[ "+items.get(i).getDiZhi()+" ]  "+items.get(i).getMingCheng());
        return convertView;
    }
}
